package com.example.gaoyang.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.gaoyang.annotation.NoAuth;
import com.example.gaoyang.domain.request.ConstructionPlanRequest;
import com.example.gaoyang.domain.vo.ConstructionPlanVO;
import com.example.gaoyang.request.Result;
import com.example.gaoyang.service.ConstructionPlanService;
import com.example.gaoyang.util.ResultUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/constructionPlan")
public class ConstructionPlanController {

    @Resource
    private ConstructionPlanService constructionPlanService;

    @PostMapping("/addConstructionPlan")
    public Result addConstructionPlan(@RequestBody ConstructionPlanRequest constructionPlanRequest) {
        constructionPlanService.addConstructionPlan(constructionPlanRequest);
        return ResultUtil.success("添加成功");
    }

    @PostMapping("/batchDeleteConstructionPlan")
    public Result batchDeleteConstructionPlan(@RequestBody ConstructionPlanRequest constructionPlanRequest) {
        constructionPlanService.batchDeleteConstructionPlan(constructionPlanRequest.getIds());
        return ResultUtil.success("批量删除成功");
    }

    @PostMapping("/getConstructionPlanList")
    @NoAuth
    public Result<List<ConstructionPlanVO>> getConstructionPlanList(@RequestBody ConstructionPlanRequest constructionPlanRequest) {
        return ResultUtil.success(constructionPlanService.getConstructionPlanList(constructionPlanRequest));
    }

    @PostMapping("/getConstructionPlanPage")
    public Result getConstructionPlanPage(Page page, @RequestBody ConstructionPlanRequest constructionPlanRequest) {
        return ResultUtil.success(constructionPlanService.getConstructionPlanPageList(page, constructionPlanRequest));
    }

    @PostMapping("/updateConstructionPlan")
    public Result updateConstructionPlan(@RequestBody ConstructionPlanRequest constructionPlanRequest) {
        constructionPlanService.updateConstructionPlan(constructionPlanRequest);
        return ResultUtil.success("修改成功");
    }

    @PostMapping("/importConstructionPlan")
    public Result importConstructionPlan(@RequestParam("file") MultipartFile file) {
        constructionPlanService.importConstructionPlan(file);
        return ResultUtil.success("导入成功");
    }

    @PostMapping("/getConstructionPlanDetail")
    public Result<ConstructionPlanVO> getConstructionPlanDetail(@RequestBody ConstructionPlanRequest constructionPlanRequest) {
        return ResultUtil.success(constructionPlanService.getConstructionPlanDetail(constructionPlanRequest));
    }

    @PostMapping("/exportConstructionPlanTemplate")
    public void exportConstructionPlanTemplate(HttpServletResponse response) {
        constructionPlanService.exportConstructionPlanTemplate(response);
    }

}
